#include "../include/task_queue.h"

int taskQueueInit(taskQueue_t *pQueue) {
    bzero(pQueue, sizeof(taskQueue_t));
    return 0;
}

int enQueue(taskQueue_t *pQueue, int netfd) {
    node_t *newNode = (node_t *)calloc(1, sizeof(node_t));
    ERROR_CHECK(newNode, NULL, "calloc when create new node");
    newNode->netfd = netfd;
    if (pQueue->pRear == NULL) {
        pQueue->pFront = newNode;
    } else {
        pQueue->pRear->pNext = newNode;
    }
    pQueue->pRear = newNode;
    pQueue->queueSize++;
    return 0;
}

int deQueue(taskQueue_t *pQueue) {
    node_t *pCurr = pQueue->pFront;
    if (pCurr != NULL) {
        pQueue->pFront = pCurr->pNext;
        if (pQueue->pFront == NULL) {
            pQueue->pRear = NULL;
        }
        free(pCurr);
        pQueue->queueSize--;
    }
    return 0;
}

